#!/usr/bin/sh
set -e

distribution=$(cat /etc/*-release|grep "^ID="|tr -d "ID=")

TZ="Asia/Shanghai"
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '${TZ}' > /etc/timezone


case "$distribution" in
    "debian")
        cp /etc/apt/sources.list /etc/apt/sources.list_bak
        sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
        package_list="zsh"
        echo "Packages to verify are installed: ${package_list}"
        apt-get update && apt-get -y install --no-install-recommends ${package_list} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
    ;;
    "ubuntu")
        cp /etc/apt/sources.list /etc/apt/sources.list_bak
        sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
        sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
        package_list="zsh"
        echo "Packages to verify are installed: ${package_list}"
        apt-get update && apt-get -y install --no-install-recommends ${package_list} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
    ;;
    "alpine"*)
        cp /etc/apk/repositories /etc/apk/repositories.bak
        sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
        package_list="zsh"
        echo "Packages to verify are installed: ${package_list}"
        apk update && apk add --no-cache ${package_list} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
    ;;
    "darwin"*)
        :"macos"
    ;;
    "cygwin" | "msys" | "win32")
        : "Windows"
    ;;
    *)
        printf '%s\n' "Unknown OS detected, aborting..." >&2
        exit 1
    ;;
esac
echo "install yarn pnpm cnpm n ts-node typescript globally"
npm -v
npm install -g npm --force
npm i -g yarn pnpm cnpm n ts-node typescript --force
npm cache clean --force














